package com.myaxuan.controller.permissions;

import com.myaxuan.common.CommonResponse;
import com.myaxuan.common.ResponseUtil;
import com.myaxuan.entity.permissions.Menu;
import com.myaxuan.service.permissions.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * Created by pc255 on 2018/4/25.
 */
@Controller
@RequestMapping("permissions")
public class MenuController {

	@Autowired
	private MenuService menuService;

	@RequestMapping("index")
	public String index(){
		return "permissions/menu";
	}

	@RequestMapping("delete")
	@ResponseBody
	public int deleteByPrimaryKey(String menuId){
		return menuService.deleteByPrimaryKey(menuId);
	}


	@RequestMapping("add")
	@ResponseBody
	public int insertSelective(Menu menu){
		return menuService.insertSelective(menu);
	}

	@RequestMapping("modify")
	@ResponseBody
	public int updateByPrimaryKeySelective(Menu menu){
		return menuService.updateByPrimaryKeySelective(menu);
	}


	@RequestMapping("find")
	@ResponseBody
	public CommonResponse selectByPrimaryKey(@RequestParam(value="id" ,defaultValue = "",required = false) String menuId,
											@RequestParam(value="page" ,defaultValue = "",required = false) Integer page,
	                                         @RequestParam(value="limit" ,defaultValue = "",required = false)Integer limit){
		return ResponseUtil.generateResponse(menuService.selectByPrimaryKey(menuId),1);
	}

	@RequestMapping("page")
	@ResponseBody
	public CommonResponse findAll(@RequestParam(value="page" ,defaultValue = "",required = false) Integer page,
	                              @RequestParam(value="limit" ,defaultValue = "",required = false)Integer limit){
		return ResponseUtil.generateResponse(menuService.findAll(page,limit),menuService.count());
	}

	@RequestMapping("source")
	@ResponseBody
	public CommonResponse findAll(@RequestParam(value="userId" ,defaultValue = "",required = false) String userId){
		return ResponseUtil.generateResponse(menuService.roleContianSource(userId));
	}
}
